﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VirtualTFS.BL;
using VirtualTFS.Core.Utility;
using VirtualTFS.DAL;
using VirtualTFS.DAL.Models;
using VirtualTFS.Models;
using VirutalTFS.Core.Utilities;


namespace VirtualTFS.Controllers
{
    public class WikiController : Controller
    {
        //
        // GET: /Wiki/

        public ActionResult New()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Home()
        {
            return View();
        }

        public ActionResult Guide()
        {
            return View();
        }

        public ActionResult Detail()
        {
            return View();
        }

        public ActionResult Edit()
        {
            return View();
        }


        [HttpPost]
        public JsonResult GetListWikiModel()
        {
            try
            {
                IList<WikiModel> list= Singleton<WikiImpl>.Instance.GetListWikiModel();
                return Json(new { Result = "OK", Records = list });
            }
            catch (Exception ex)
            {
                return Json(new { Result = "Fail", Message = ex.Message });
            }
        }

        public bool CreateWiki(WikiModel model)
        {
            model.Id = GuidUtils.NewSeqGuid();
            var wikiImpl = new WikiImpl();
            wikiImpl.CreateWiki(model);
            return true;
        }

        public bool EditWiki(WikiModel model)
        {
            var wikiImpl = new WikiImpl();
            wikiImpl.EditWiki(model);
            return true;
        }

        public bool Delete(WikiModel model)
        {
            var wikiImpl = new WikiImpl();
            wikiImpl.DeleteWiki(model);
            return true;
        }

        public JsonResult GetProjectList()
        {
            var viewModel = new ProjectViewModel {Projects = Singleton<ProjectImpl>.Instance.GetListProject()};
            return Json(viewModel);
        }

        public JsonResult GetWikiInfo(System.Guid id)
        {
            Wiki wiki = Singleton<WikiImpl>.Instance.GetWikiInfo(id);
            var wikiInfo = new WikiModel(wiki);
            var viewModel = new WikiViewModel {WikiInfo = wikiInfo};
           
            return Json(viewModel, JsonRequestBehavior.AllowGet);
        }
    }
}
